﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using Software_2Project.Forms;
using Software_2Project.DB_Layer;
using System.Text.RegularExpressions;

namespace Software_2Project.Logic_Layer
{
    public class Logic_withdraw
    {
        public bool put(int acconum, int balance)
        {
            //=================Validating Empty
            if (acconum.ToString() == null || balance < 0 || balance.ToString() == null)
                return false;

            //=================Validating Numbers Only
            string patternWithdraw = @"^\d+$";
            bool matchWithdraw   = Regex.IsMatch(balance.ToString(), patternWithdraw);
            bool matchWithdraw_1 = Regex.IsMatch(acconum.ToString(), patternWithdraw);

            if (matchWithdraw==false || matchWithdraw_1==false)
                return false;

            DB_withdraw dal = new DB_withdraw();
            //dal.balance = balance;
            //dal.acconum = acconum;
            bool inc = false;

            if (dal.checkWithdraw(acconum,balance))
            {

                DataTable dt = dal.withdraw(acconum,balance);



                foreach (DataRow dRow in dt.Rows)
                {

                    if ((acconum == int.Parse(dRow["acconum"].ToString())))
                    {


                        inc = true;

                    }

                }
                //if (!found)

                //{
                //    return false;
                //}
            }
            return inc;

        }

        // public string acconum { get; set; }
    }
}
